import axios from 'axios'
import {message} from 'antd'
import Qs from "qs";

export default function api(url,data={},type='GET',headers={}){
    return  new Promise((resolve,reject)=>{
        let promise
        if(type==="GET"){
            promise=axios.get(url,{
                params:data 
            })
        }else{
            if(headers['Content-Type']==="application/x-www-form-urlencoded"){
                data=Qs.stringify(data)
            }
            promise=axios({
                url,
                data,
                method: 'POST', //请求方式
                headers
            })
        }
        //成功
        promise.then(res=>{
            resolve(res.data)
        }).catch(err=>{
            message.error("请求出错:"+err.info)
        })
    })

}

